FORM frm_init .
    p_gjahr = sy-datum+0(4).
    p_monat = sy-datum+4(2) - 1.
    p_versn = 'HXCN'.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_CHECK_INPUT
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_check_input .
    DATA: lv_str TYPE string.
  
  ***********add by xx-yangyu begin 21.01.2021 19:23:30 ****************
    IF s_bukrs IS INITIAL.
      MESSAGE '公司代码必填' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.
    IF p_gjahr IS INITIAL.
      MESSAGE '会计年度必填' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.
    IF p_monat IS INITIAL.
      MESSAGE '期间必填' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ELSE.
      IF p_monat NOT BETWEEN '01' AND '16'.
        MESSAGE '允许输入的期间01~16' TYPE 'S' DISPLAY LIKE 'E'.
        LEAVE LIST-PROCESSING.
      ENDIF.
    ENDIF.
    IF p_versn IS INITIAL.
      MESSAGE '报表版本必填' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.
  ***********add end  21.01.2021 19:23:30*******************************
  
    CLEAR gt_bukrs.
    SELECT *
    INTO TABLE gt_bukrs
    FROM t001
    WHERE bukrs IN s_bukrs.
  
  
    LOOP AT gt_bukrs INTO gs_bukrs.
      AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
      ID 'ACTVT' FIELD '03'
      ID 'BUKRS' FIELD  gs_bukrs-bukrs.
      IF sy-subrc <> 0.
        lv_str = TEXT-m02 && gs_bukrs-bukrs.
        MESSAGE lv_str TYPE 'S' DISPLAY LIKE 'E'.
        STOP.
      ENDIF.
    ENDLOOP.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_00
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_00 .
    CLEAR:gv_up_year.
    IF p_rb_02 = 'X'.
      gv_up_year = p_gjahr - 1.
    ENDIF.
  
    CLEAR:gv_butxt.
    IF lines( gt_bukrs[] ) GT 1.
      gv_butxt = '*'.
    ELSE.
      READ TABLE gt_bukrs INTO gs_bukrs INDEX 1.
      IF sy-subrc EQ 0.
        gv_butxt = gs_bukrs-butxt.
      ENDIF.
    ENDIF.
  
    IF p_monat GE '12'.
      gv_zdate = p_gjahr && '1201'.
    ELSE.
      gv_zdate = p_gjahr && p_monat && '01'.
    ENDIF.
  
    PERFORM frm_last_day_of_months USING gv_zdate CHANGING gv_zdate.
    gv_danwei = '元'.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_01
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_01.
    DATA:lv_dspra TYPE t011-dspra.
  
    SELECT SINGLE dspra INTO lv_dspra FROM t011 WHERE versn = p_versn.
  
    REFRESH:gt_x011q.
    CALL FUNCTION 'FI_IMPORT_BALANCE_SHEET_TEXT'
      EXPORTING
        sprache        = lv_dspra
        version        = p_versn
      TABLES
        x011q          = gt_x011q
      EXCEPTIONS
        text_not_found = 1
        OTHERS         = 2.
    IF sy-subrc <> 0.
    ENDIF.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_02
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_02.
    CALL FUNCTION 'FI_IMPORT_BALANCE_SHEET_POS'
      EXPORTING
        version           = p_versn
      TABLES
        i011z             = gt_i011z
        x011p             = gt_x011p
        x011s             = gt_x011s
      EXCEPTIONS
        new_balance_sheet = 1
        OTHERS            = 2.
    IF sy-subrc <> 0.
    ENDIF.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_03
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_03 .
  *  PERFORM frm_add_i011z USING '90-2' '5000000000' '5999999999'.
  *  PERFORM frm_add_i011z USING '90-2' '6000000000' '6999999999'.
  *  PERFORM frm_add_i011z USING '90-2' '8000000000' '8999999999'.
  ENDFORM.
  
  *&---------------------------------------------------------------------*
  *& Form frm_get_data_52
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_50.
    FIELD-SYMBOLS:<lfs_x011p> TYPE rf011p,
                  <lfs_x011s> TYPE rf011s,
                  <lfs_x011q> TYPE rf011q.
    DATA:lv_top_ergsl TYPE rf011p-ergsl.
  
    REFRESH:gt_data.
    LOOP AT gt_x011p ASSIGNING <lfs_x011p>.
      MOVE-CORRESPONDING <lfs_x011p> TO gt_data.
  
      READ TABLE gt_x011s ASSIGNING <lfs_x011s> WITH KEY ergsl = <lfs_x011p>-ergsl.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING <lfs_x011s> TO gt_data.
      ENDIF.
  
      READ TABLE gt_x011q  ASSIGNING <lfs_x011q> WITH KEY ergsl = <lfs_x011p>-ergsl.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING <lfs_x011q> TO gt_data.
      ENDIF.
  
      gt_data-zzzxc = gt_data-ergsl.
      PERFORM frm_alpha_input CHANGING gt_data-zzzxc.
  
      IF gt_data-stufe = '1'.
        lv_top_ergsl  = gt_data-ergsl.
      ENDIF.
      gt_data-zztop = lv_top_ergsl.
  
      PERFORM frm_get_text USING gt_data-stufe gt_data-zztop CHANGING gt_data-txt45.
  
      IF gt_data-zztop <> gc_ergsl_left AND gt_data-zztop <> gc_ergsl_right .
        CONTINUE.
      ENDIF.
      SEARCH gt_data-ergsl FOR '-'.
      IF sy-subrc = 0.
        gt_data-zzdel = 'X'.
      ENDIF.
  
      APPEND gt_data.
      CLEAR  gt_data.
    ENDLOOP.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_51
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_51.
    DATA:lt_data  TYPE gty_data  OCCURS 0 WITH HEADER LINE,
         lv_stufe TYPE rf011p-stufe.
    FIELD-SYMBOLS:<lfs_data> TYPE gty_data.
  
    LOOP AT gt_data ASSIGNING <lfs_data>.
      lt_data[] = gt_data[].
      DELETE lt_data WHERE setnr >= <lfs_data>-setnr.
  
      lv_stufe = <lfs_data>-stufe - 1.
      SORT lt_data BY setnr DESCENDING.
      READ TABLE lt_data WITH KEY stufe = lv_stufe.
      IF sy-subrc = 0.
        <lfs_data>-zzzup = lt_data-ergsl.
      ENDIF.
    ENDLOOP.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form frm_get_data_52
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_52.
    DATA:lt_fagl  TYPE gty_faglflext  OCCURS 0 WITH HEADER LINE,
         lv_monat TYPE bkpf-monat,
         lv_fname TYPE char50,
         lv_index TYPE sy-tabix.
    FIELD-SYMBOLS:<lfs_fagl>  TYPE gty_faglflext,
                  <lfs_i011z> TYPE rf011z,
                  <lfs_value>.
  
    SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_fagl
    FROM faglflext
    WHERE ( ryear = p_gjahr OR ryear = gv_up_year )
    AND rbukrs IN s_bukrs.
    REFRESH:gt_racct.
  
    LOOP AT lt_fagl ASSIGNING <lfs_fagl>.
      lv_monat = '01'.
      <lfs_fagl>-cost1 = <lfs_fagl>-hslvt.
      <lfs_fagl>-cost2 = <lfs_fagl>-hslvt.
      <lfs_fagl>-cost3 = <lfs_fagl>-hslvt.
      <lfs_fagl>-cost4 = <lfs_fagl>-hslvt.
  
  ***********delete by xx-yangyu begin 23.01.2021 11:27:54 ****************
  *    IF <lfs_fagl>-racct = '2221011100'.
  *      gt_racct-ryear = <lfs_fagl>-ryear.
  *      gt_racct-drcrk = <lfs_fagl>-drcrk.
  *      gt_racct-racct = <lfs_fagl>-racct.
  *      gt_racct-cost1 = <lfs_fagl>-hslvt.
  *      gt_racct-cost2 = <lfs_fagl>-hslvt.
  *      gt_racct-cost3 = <lfs_fagl>-hslvt.
  *      gt_racct-cost4 = <lfs_fagl>-hslvt.
  *    ENDIF.
  ***********delete end  23.01.2021 11:27:54*******************************
  
      WHILE lv_monat <= '12'.
        lv_fname = '<lfs_fagl>-hsl' && lv_monat.
        ASSIGN (lv_fname) TO <lfs_value>.
  
        IF lv_monat < p_monat."上月期末数
          <lfs_fagl>-cost2 = <lfs_fagl>-cost2 + <lfs_value>.
  ***********delete by xx-yangyu begin 23.01.2021 11:28:22 ****************
  *        IF <lfs_fagl>-racct = '2221011100'.
  *          gt_racct-cost2 = gt_racct-cost2 + <lfs_value>.
  *        ENDIF.
  ***********delete end  23.01.2021 11:28:22*******************************
        ENDIF.
  
        IF lv_monat = '01'."年初数
          <lfs_fagl>-cost3 = <lfs_fagl>-cost3 + <lfs_value>.
  ***********delete by xx-yangyu begin 23.01.2021 11:28:35 ****************
  *        IF <lfs_fagl>-racct = '2221011100'.
  *          gt_racct-cost3 = gt_racct-cost3 + <lfs_value>.
  *        ENDIF.
  ***********delete end  23.01.2021 11:28:35*******************************
        ENDIF.
  
  
        IF lv_monat <= p_monat."期末数
          <lfs_fagl>-cost4 = <lfs_fagl>-cost4 + <lfs_value>.
  ***********delete by xx-yangyu begin 23.01.2021 11:28:45 ****************
  *        IF <lfs_fagl>-racct = '2221011100'.
  *          gt_racct-cost4 = gt_racct-cost4 + <lfs_value>.
  *        ENDIF.
  ***********delete end  23.01.2021 11:28:45*******************************
        ENDIF.
        lv_monat = lv_monat + 1.
      ENDWHILE.
  ***********delete by xx-yangyu begin 23.01.2021 11:28:59 ****************
  *    IF <lfs_fagl>-racct = '2221011100'.
  *      COLLECT gt_racct.
  *      CLEAR   gt_racct.
  *    ENDIF.
  ***********delete end  23.01.2021 11:28:59*******************************
  
  
      LOOP AT gt_i011z ASSIGNING <lfs_i011z> WHERE vonkt <= <lfs_fagl>-racct AND bilkt >= <lfs_fagl>-racct.
  ***********delete by xx-yangyu begin 23.01.2021 11:29:14 ****************
  *      IF <lfs_fagl>-racct = '2221011100'."单独处理
  *        CONTINUE.
  *      ENDIF.
  ***********delete end  23.01.2021 11:29:14*******************************
  
        READ TABLE gt_data WITH KEY ergsl = <lfs_i011z>-ergso .
        IF sy-subrc = 0.
          lv_index = sy-tabix.
  
          IF <lfs_fagl>-ryear = gv_up_year.
            "上年同期数(上年期末数)
            gt_data-cost1 = gt_data-cost1 + <lfs_fagl>-cost4.
  *          "上年年初数(年初数)
  *          gt_data-cost9 = gt_data-cost9 + <lfs_fagl>-cost1.
          ELSE.
            "上月期末数(期初数)
            gt_data-cost2 = gt_data-cost2 + <lfs_fagl>-cost2.
  
            "年初数(年初数)
            gt_data-cost3 = gt_data-cost3 + <lfs_fagl>-cost1.
  
            "期末数
            gt_data-cost4 = gt_data-cost4 + <lfs_fagl>-cost4.
          ENDIF.
  
          MODIFY gt_data INDEX lv_index.
          CLEAR  gt_data.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
  ENDFORM.
  **&---------------------------------------------------------------------*
  **& Form FRM_GET_DATA_53
  **&---------------------------------------------------------------------*
  **& text
  **&---------------------------------------------------------------------*
  **& -->  p1        text
  **& <--  p2        text
  **&---------------------------------------------------------------------*
  *FORM frm_get_data_53.
  *  FIELD-SYMBOLS:<lfs_racct>  TYPE gty_racct.
  *  DATA:ls_data  TYPE gty_data,
  *       lv_index TYPE sy-tabix.
  *  DATA: lv_cost1 TYPE fins_vtcur12,
  *        lv_cost2 TYPE fins_vtcur12,
  *        lv_cost3 TYPE fins_vtcur12,
  *        lv_cost4 TYPE fins_vtcur12.
  *  DATA: BEGIN OF ls_list,
  *          prkey   TYPE rf011p-prkey,
  *          ergsl   TYPE rf011p-ergsl,
  *          summe   TYPE rf011p-summe,
  *          stufe   TYPE rf011p-stufe,
  *          setnr   TYPE rf011s-setnr,
  *          txt45   TYPE rf011q-txt45,
  *          zztop   TYPE rf011p-ergsl,
  *          zzzup   TYPE rf011p-ergsl,
  *          zzzxc   TYPE rf011p-ergsl,
  *          zzdel   TYPE char1,
  *          cost1   TYPE fins_vtcur12, ",上年同期数
  *          cost2   TYPE fins_vtcur12, ",上年同期累计
  *          cost3   TYPE fins_vtcur12, ",上月发生
  *          cost4   TYPE fins_vtcur12, ",本月发生
  *          cost5   TYPE fins_vtcur12, ",本年累计
  ************add by xx-yangyu begin 10.03.2021 13:50:43 ****************
  *          cost6   TYPE fins_vtcur12,
  *          cost7   TYPE fins_vtcur12,
  *          cost8   TYPE fins_vtcur12,
  *          cost9   TYPE fins_vtcur12,
  *          "按利润中心细分
  *          cost01a TYPE fins_vtcur12, "本月数
  *          cost01b TYPE fins_vtcur12, "本年累计数
  *          cost02a TYPE fins_vtcur12, "本月数
  *          cost02b TYPE fins_vtcur12, "本年累计数
  *          cost03a TYPE fins_vtcur12, "本月数
  *          cost03b TYPE fins_vtcur12, "本年累计数
  *          cost04a TYPE fins_vtcur12, "本月数
  *          cost04b TYPE fins_vtcur12, "本年累计数
  *          cost05a TYPE fins_vtcur12, "本月数
  *          cost05b TYPE fins_vtcur12, "本年累计数
  *          cost06a TYPE fins_vtcur12, "本月数
  *          cost06b TYPE fins_vtcur12, "本年累计数
  *          cost07a TYPE fins_vtcur12, "本月数
  *          cost07b TYPE fins_vtcur12, "本年累计数
  *          cost08a TYPE fins_vtcur12, "本月数
  *          cost08b TYPE fins_vtcur12, "本年累计数
  *          cost09a TYPE fins_vtcur12, "本月数
  *          cost09b TYPE fins_vtcur12, "本年累计数
  *          cost10a TYPE fins_vtcur12, "本月数
  *          cost10b TYPE fins_vtcur12, "本年累计数
  *          cost11a TYPE fins_vtcur12, "本月数
  *          cost11b TYPE fins_vtcur12, "本年累计数
  ************add end  10.03.2021 13:50:43*******************************
  *        END OF ls_list.
  *  DATA: lt_list LIKE TABLE OF ls_list.
  *  DATA: lv_monat TYPE bkpf-monat,
  *        lv_gjahr TYPE bkpf-gjahr.
  *
  *  CLEAR:lv_cost1,lv_cost2,lv_cost3,lv_cost4.
  *
  *  LOOP AT gt_racct ASSIGNING <lfs_racct>.
  *    CLEAR:ls_data.
  *    lv_cost1 = lv_cost1 + <lfs_racct>-cost1.
  *    lv_cost2 = lv_cost2 + <lfs_racct>-cost2.
  *    lv_cost3 = lv_cost3 + <lfs_racct>-cost3.
  *    lv_cost4 = lv_cost4 + <lfs_racct>-cost4.
  *  ENDLOOP.
  *
  *  "对于2221020000科目判断其余额，如果余额为借方(金额大于0)，则把借方金额调整到项目14，同时把对应的金额从48应交税额项目下扣除。
  **  READ TABLE gt_data WITH KEY ergsl = '48'."modify by xx-yangyu 20210121----编码48改为46
  **  READ TABLE gt_data WITH KEY ergsl = '46'."modify by xx-yangyu 20210128----编码46改为45
  *  READ TABLE gt_data WITH KEY ergsl = '45'.
  *  IF sy-subrc = 0.
  *    lv_index = sy-tabix."原值为负数
  *    IF lv_cost1 LT 0.
  *      gt_data-cost1 = gt_data-cost1 + lv_cost1.
  *    ENDIF.
  *    IF lv_cost2 LT 0.
  *      gt_data-cost2 = gt_data-cost2 + lv_cost2.
  *    ENDIF.
  *    IF lv_cost3 LT 0.
  *      gt_data-cost3 = gt_data-cost3 + lv_cost3.
  *    ENDIF.
  *    IF lv_cost4 LT 0.
  *      gt_data-cost4 = gt_data-cost4 + lv_cost4.
  *    ENDIF.
  *    MODIFY gt_data INDEX lv_index.
  *    CLEAR gt_data.
  *  ENDIF.
  *
  *  READ TABLE gt_data WITH KEY ergsl = '14'.
  *  IF sy-subrc = 0.
  *    lv_index = sy-tabix.
  *    IF lv_cost1 GT 0.
  *      gt_data-cost1 = gt_data-cost1 + lv_cost1.
  *    ENDIF.
  *    IF lv_cost2 GT 0.
  *      gt_data-cost2 = gt_data-cost2 + lv_cost2.
  *    ENDIF.
  *    IF lv_cost3 GT 0.
  *      gt_data-cost3 = gt_data-cost3 + lv_cost3.
  *    ENDIF.
  *    IF lv_cost4 GT 0.
  *      gt_data-cost4 = gt_data-cost4 + lv_cost4.
  *    ENDIF.
  *    MODIFY gt_data INDEX lv_index.
  *    CLEAR gt_data.
  *  ENDIF.
  *
  ***从利润表获取数据----赋值给“未分配利润”
  **  SUBMIT zsy_fi_005
  **                WITH s_bukrs IN s_bukrs
  **                WITH p_gjahr = p_gjahr
  **                WITH p_monat = p_monat
  **                WITH p_versn = p_versn
  **                WITH s_prctr IN s_prctr[]
  **                WITH p_rb_01 = ''
  **                WITH p_rb_02 = ''
  **                WITH p_rb_03 = 'X'
  ***                WITH p_chk = 'X'"add by xx-yangyu 20210125    modify by xx-yangyu 20210224
  ***                WITH p_chk = p_chk "delete by xx-yangyu 20210308
  **                AND RETURN.
  **
  **  IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  **  FREE MEMORY ID 'ZSY_FI_005'.
  **
  **  CLEAR: gv_p68_adj01,gv_p68_adj02.
  ***  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P23'.
  **  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P24'.
  **  IF sy-subrc EQ 0.
  ***    READ TABLE gt_data WITH KEY ergsl = '73'. "modify by xx-yangyu 20210121----编码73改为70
  ***    READ TABLE gt_data WITH KEY ergsl = '70'."modify by xx-yangyu 20210128----编码70改为68
  **    READ TABLE gt_data WITH KEY ergsl = '68'.
  **    IF sy-subrc EQ 0."取负数，后面会取相反数
  **      CLEAR lv_index.
  **      lv_index = sy-tabix.
  **********modify by xx-yangyu begin 27.03.2021 10:18:06 ****************
  ***      ""期末数=当前期末数+利润表本年累计
  ***      gt_data-cost4 = gt_data-cost4 - ls_list-cost5.
  ***      ""上年同期数=上年同期数+利润表上年同期累计
  ***      gt_data-cost1 = gt_data-cost1 - ls_list-cost2.
  **
  **      IF p_rb_03 EQ ''.
  **        ""期末数=当前期末数+利润表本年累计
  **        gt_data-cost4 = gt_data-cost4 - ls_list-cost9.
  **        ""上年同期数=上年同期数+利润表上年同期累计
  **        gt_data-cost1 = gt_data-cost1 - ls_list-cost2.
  **      ELSE.
  **        "账面
  **        "期末数=当前期末数+利润表本年累计
  **        gt_data-cost4 = gt_data-cost4 - ls_list-cost5.
  **        ""上年同期数=上年同期数+利润表上年同期累计
  **        gt_data-cost1 = gt_data-cost1 - ls_list-cost2.
  **        "调整期末
  ***        gt_data-cost6 = gt_data-cost6 - ls_list-cost7.
  **        gv_p68_adj02 = 0 - ls_list-cost7.
  **        "调整后期末
  **        gt_data-cost8 = gt_data-cost8 - ls_list-cost9.
  **      ENDIF.
  **********modify end 27.03.2021 10:18:06 *******************************
  **      MODIFY gt_data INDEX lv_index TRANSPORTING cost1 cost4 cost6 cost8.
  **    ENDIF.
  **  ENDIF.
  **
  **  CLEAR: lv_gjahr,lv_monat.
  **  IF p_monat EQ '01'.
  **    lv_gjahr = p_gjahr - 1.
  **    lv_monat = '16'.
  **  ELSE.
  **    lv_gjahr = p_gjahr.
  **    lv_monat = p_monat - 1.
  **  ENDIF.
  **  SUBMIT zsy_fi_005
  **                WITH s_bukrs IN s_bukrs
  **                WITH p_gjahr = lv_gjahr
  **                WITH p_monat = lv_monat
  **                WITH p_versn = p_versn
  **                WITH s_prctr IN s_prctr[]
  **                WITH p_rb_01 = ''
  **                WITH p_rb_02 = ''
  **                WITH p_rb_03 = 'X'
  ***                WITH p_chk = 'X'"add by xx-yangyu 20210125   modify by xx-yangyu 20210224
  ***                WITH p_chk = p_chk "delete by xx-yangyu 20210308
  **                AND RETURN.
  **
  **  IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  **  FREE MEMORY ID 'ZSY_FI_005'.
  **
  ***  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P23'.
  **  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P24'.
  **  IF sy-subrc EQ 0.
  ***    READ TABLE gt_data WITH KEY ergsl = '73'. "modify by xx-yangyu 20210121----编码73改为70
  ***    READ TABLE gt_data WITH KEY ergsl = '70'."modify by xx-yangyu 20210128----编码70改为68
  **    READ TABLE gt_data WITH KEY ergsl = '68'.
  **    IF sy-subrc EQ 0."取负数，后面会取相反数
  **      CLEAR lv_index.
  **      lv_index = sy-tabix.
  **      ""上月期末数=上月期末数+利润表上个月的本年累计
  **********modify by xx-yangyu begin 27.03.2021 10:32:09 ****************
  ***      gt_data-cost2 = gt_data-cost2 - ls_list-cost5.
  **
  **      IF p_rb_03 EQ ''.
  **        gt_data-cost2 = gt_data-cost2 - ls_list-cost9.
  **      ELSE.
  **        gt_data-cost2 = gt_data-cost2 - ls_list-cost5.
  **      ENDIF.
  **********modify end 27.03.2021 10:32:09 *******************************
  **      MODIFY gt_data INDEX lv_index TRANSPORTING cost2.
  **    ENDIF.
  **  ENDIF.
  *
  *  lv_gjahr = p_gjahr - 1.
  *  lv_monat = '12'.
  **  SUBMIT zsy_fi_005
  **  WITH s_bukrs IN s_bukrs
  **  WITH p_gjahr = lv_gjahr
  **  WITH p_monat = lv_monat
  **  WITH p_versn = p_versn
  **  WITH s_prctr IN s_prctr[]
  **  WITH p_rb_01 = ''
  **  WITH p_rb_02 = ''
  **  WITH p_rb_03 = 'X'
  ***              WITH p_chk = 'X'"add by xx-yangyu 20210125   modify by xx-yangyu 20210224
  ***              WITH p_chk = p_chk "delete by xx-yangyu 20210308
  **  AND RETURN.
  *
  *  IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  *  FREE MEMORY ID 'ZSY_FI_005'.
  *  CLEAR: gv_p68_adj01.
  **  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P23'.
  *  READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P29'.
  *  IF sy-subrc EQ 0.
  **    READ TABLE gt_data WITH KEY ergsl = '73'."modify by xx-yangyu 20210121----编码73改为70
  **    READ TABLE gt_data WITH KEY ergsl = '70'."modify by xx-yangyu 20210128----编码70改为68
  *    READ TABLE gt_data WITH KEY ergsl = '68'.
  *    IF sy-subrc EQ 0."取负数，后面会取相反数
  *      CLEAR lv_index.
  *      lv_index = sy-tabix.
  *      ""年初数=年初数+利润表上一年12月份本年累计
  *********modify by xx-yangyu begin 27.03.2021 10:31:32 ****************
  **      gt_data-cost3 = gt_data-cost3 - ls_list-cost5.
  *
  *      IF p_rb_03 EQ ''.
  *        "年初数
  **        gt_data-cost3 = gt_data-cost3 - ls_list-cost9."20220214注释
  *        gt_data-cost3 = gt_data-cost3 - ls_list-cost7.      "20220214修改
  *      ELSE.
  *        "账面年初数
  **        gt_data-cost3 = gt_data-cost3 - ls_list-cost5."20220214注释
  *        "调整年初
  **        gt_data-cost5 = gt_data-cost5 - ls_list-cost7.
  *        gv_p68_adj01 = 0 - ls_list-cost7.
  *        "调整后年初
  *        gt_data-cost7 = gt_data-cost7 - ls_list-cost7.      "20220214修改
  **        gt_data-cost7 = gt_data-cost7 - ls_list-cost9."20220214注释
  *      ENDIF.
  *********modify end 27.03.2021 10:31:32 *******************************
  *      MODIFY gt_data INDEX lv_index TRANSPORTING cost3 cost5 cost7.
  *    ENDIF.
  *  ENDIF.
  *
  *
  *
  **********modify by 10016381 畅小博 begin 20210705 ****************
  *  IF ( p_monat < 12 AND p_gjahr = '2020' ) OR p_gjahr <> '2020' ."账面期末数：2020年12月份取值不需要特殊处理，其他的需要到利润表取值
  *    SUBMIT zsy_fi_005
  *    WITH s_bukrs IN s_bukrs
  *    WITH p_gjahr = p_gjahr
  *    WITH p_monat = p_monat
  *    WITH p_versn = p_versn
  *    WITH s_prctr IN s_prctr[]
  *    WITH p_rb_01 = ''
  *    WITH p_rb_02 = ''
  *    WITH p_rb_03 = 'X'
  *    AND RETURN.
  *
  *    IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  *    FREE MEMORY ID 'ZSY_FI_005'.
  *
  *    CLEAR: gv_p68_adj02.
  *    READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P29'.
  *    IF sy-subrc EQ 0.
  *      READ TABLE gt_data WITH KEY ergsl = '68'.
  *      IF sy-subrc EQ 0."取负数，后面会取相反数
  *        CLEAR lv_index.
  *        lv_index = sy-tabix.
  *        IF p_rb_03 EQ ''.
  *          ""期末数=当前期末数+利润表本年累计
  *          gt_data-cost4 = gt_data-cost4 - ls_list-cost9.
  *        ELSE.
  *          "账面
  *          "期末数=当前期末数+利润表本年累计
  *          gt_data-cost4 = gt_data-cost4 - ls_list-cost5.
  *          gv_p68_adj02 = 0 - ls_list-cost7.
  *          "调整后期末
  *          gt_data-cost8 = gt_data-cost8 - ls_list-cost9.
  *        ENDIF.
  *********modify end 27.03.2021 10:18:06 *******************************
  *        MODIFY gt_data INDEX lv_index TRANSPORTING cost4 cost8.
  *      ENDIF.
  *    ENDIF.
  *  ENDIF.
  *  IF ( p_monat < 12 AND p_gjahr = '2021' ) OR p_gjahr <> '2021' ."上年同期数：2021年12月份取值不需要特殊处理，其他的需要到利润表取值
  *    SUBMIT zsy_fi_005
  *    WITH s_bukrs IN s_bukrs
  *    WITH p_gjahr = p_gjahr
  *    WITH p_monat = p_monat
  *    WITH p_versn = p_versn
  *    WITH s_prctr IN s_prctr[]
  *    WITH p_rb_01 = ''
  *    WITH p_rb_02 = 'X'
  *    WITH p_rb_03 = ''
  *    AND RETURN.
  *    IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  *    FREE MEMORY ID 'ZSY_FI_005'.
  *    READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P29'.
  *    IF sy-subrc EQ 0.
  *      READ TABLE gt_data WITH KEY ergsl = '68'.
  *      IF sy-subrc EQ 0."取负数，后面会取相反数
  *        CLEAR lv_index.
  *        lv_index = sy-tabix.
  *        "上年同期数=上年同期账面余额+利润表上年同期累计——20210705修改
  *        gt_data-cost1 = gt_data-cost1 - ls_list-cost2.
  *
  *        MODIFY gt_data INDEX lv_index TRANSPORTING cost1.
  *      ENDIF.
  *    ENDIF.
  *  ENDIF.
  *
  *
  *  IF ( p_monat <> '01' AND  p_gjahr = '2021' ) OR p_gjahr <> '2021' ."上月期末取值：2021年1月份的上月期末取值不需要特殊处理，其他的需要到利润表取值
  *    CLEAR: lv_gjahr,lv_monat.
  *    IF p_monat = '01'.
  *      lv_gjahr = p_gjahr - 1.
  *      lv_monat = '12'.
  *    ELSE.
  *      lv_gjahr = p_gjahr.
  *      lv_monat = p_monat - 1.
  *    ENDIF.
  *
  *    SUBMIT zsy_fi_005
  *    WITH s_bukrs IN s_bukrs
  *    WITH p_gjahr = lv_gjahr
  *    WITH p_monat = lv_monat
  *    WITH p_versn = p_versn
  *    WITH s_prctr IN s_prctr[]
  *    WITH p_rb_01 = ''
  *    WITH p_rb_02 = ''
  *    WITH p_rb_03 = 'X'
  *    AND RETURN.
  *
  *    IMPORT p1 = lt_list FROM MEMORY ID 'ZSY_FI_005'.
  *    FREE MEMORY ID 'ZSY_FI_005'.
  *
  **    READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P28'.
  *    READ TABLE lt_list INTO ls_list WITH KEY ergsl = 'P29'.
  *    IF sy-subrc EQ 0.
  *      READ TABLE gt_data WITH KEY ergsl = '68'.
  *      IF sy-subrc EQ 0."取负数，后面会取相反数
  *        CLEAR lv_index.
  *        lv_index = sy-tabix.
  *        IF p_rb_03 EQ ''.
  *          gt_data-cost2 = gt_data-cost2 - ls_list-cost9.
  *        ELSE.
  *          gt_data-cost2 = gt_data-cost2 - ls_list-cost5.
  *        ENDIF.
  *        MODIFY gt_data INDEX lv_index TRANSPORTING cost2.
  *      ENDIF.
  *    ENDIF.
  *  ENDIF.
  *
  **
  **    "
  **********modify by 10016381 畅小博 end 20210705 ****************
  *
  *ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form frm_get_data_54
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_54.
    FIELD-SYMBOLS:<lfs_data> TYPE gty_data.
    DATA:lt_data TYPE gty_data  OCCURS 0 WITH HEADER LINE.
  
    SORT gt_data BY stufe DESCENDING.
  
    LOOP AT gt_data ASSIGNING <lfs_data>.
      lt_data[] = gt_data[].
      DELETE lt_data WHERE zzzup <> <lfs_data>-ergsl.
  
      LOOP AT lt_data.
        <lfs_data>-cost1 = <lfs_data>-cost1 + lt_data-cost1.
        <lfs_data>-cost2 = <lfs_data>-cost2 + lt_data-cost2.
        <lfs_data>-cost3 = <lfs_data>-cost3 + lt_data-cost3.
        <lfs_data>-cost4 = <lfs_data>-cost4 + lt_data-cost4.
  *      IF <lfs_data>-ergsl = '68'.
  *        <lfs_data>-cost1 = <lfs_data>-cost1 + lt_data-cost9.
  *        <lfs_data>-cost2 = <lfs_data>-cost2 + lt_data-cost3.
  *        <lfs_data>-cost4 = <lfs_data>-cost4 + lt_data-cost3.
  *      ELSE.
  *        <lfs_data>-cost1 = <lfs_data>-cost1 + lt_data-cost1.
  *        <lfs_data>-cost2 = <lfs_data>-cost2 + lt_data-cost2.
  *        <lfs_data>-cost4 = <lfs_data>-cost4 + lt_data-cost4.
  *      ENDIF.
  ***********add by xx-yangyu begin 27.03.2021 11:14:26 ****************
        <lfs_data>-cost5 = <lfs_data>-cost5 + lt_data-cost5.
        <lfs_data>-cost6 = <lfs_data>-cost6 + lt_data-cost6.
        <lfs_data>-cost7 = <lfs_data>-cost7 + lt_data-cost7.
        <lfs_data>-cost8 = <lfs_data>-cost8 + lt_data-cost8.
  ***********add end  27.03.2021 11:14:26*******************************
      ENDLOOP.
    ENDLOOP.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_DATA_90
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_get_data_90 .
    DATA:lt_data1 TYPE gty_data  OCCURS 0 WITH HEADER LINE,
         lt_data2 TYPE gty_data  OCCURS 0 WITH HEADER LINE,
         lv_index TYPE sy-tabix.
    FIELD-SYMBOLS:<lfs_data> TYPE gty_data.
  
    DELETE gt_data WHERE zzdel = 'X'.
    SORT:gt_data BY zzzxc.
  
    lt_data1[] = gt_data[].
    lt_data2[] = gt_data[].
    DELETE lt_data1 WHERE zztop <> gc_ergsl_left.
    DELETE lt_data2 WHERE zztop <> gc_ergsl_right.
  
    REFRESH:gt_list.
    LOOP AT lt_data1 ASSIGNING <lfs_data>.
      gt_list-zzzxca = <lfs_data>-zzzxc.
      gt_list-txt45a = <lfs_data>-txt45.
      gt_list-cost1a = <lfs_data>-cost1.
      gt_list-cost2a = <lfs_data>-cost2.
      gt_list-cost3a = <lfs_data>-cost3.
      gt_list-cost4a = <lfs_data>-cost4.
  ***********add by xx-yangyu begin 27.03.2021 11:15:24 ****************
      gt_list-cost5a = <lfs_data>-cost5.
      gt_list-cost6a = <lfs_data>-cost6.
      gt_list-cost7a = <lfs_data>-cost7.
      gt_list-cost8a = <lfs_data>-cost8.
  ***********add end  27.03.2021 11:15:24*******************************
      APPEND gt_list.
      CLEAR  gt_list.
    ENDLOOP.
  
    LOOP AT lt_data2 ASSIGNING <lfs_data>.
      lv_index = sy-tabix.
      READ TABLE gt_list INDEX lv_index.
      IF sy-subrc = 0.
        gt_list-zzzxcb = <lfs_data>-zzzxc.
        gt_list-txt45b = <lfs_data>-txt45.
        gt_list-cost1b =  <lfs_data>-cost1.
        gt_list-cost2b =  <lfs_data>-cost2.
        gt_list-cost3b =  <lfs_data>-cost3.
        gt_list-cost4b =  <lfs_data>-cost4.
  ***********add by xx-yangyu begin 27.03.2021 11:15:53 ****************
        gt_list-cost5b =  <lfs_data>-cost5.
        gt_list-cost6b =  <lfs_data>-cost6.
        gt_list-cost7b =  <lfs_data>-cost7.
        gt_list-cost8b =  <lfs_data>-cost8.
  ***********add end  27.03.2021 11:15:53*******************************
        MODIFY gt_list INDEX lv_index.
        CLEAR  gt_list.
      ELSE.
        gt_list-zzzxcb = <lfs_data>-zzzxc.
        gt_list-txt45b = <lfs_data>-txt45.
        gt_list-cost1b =  <lfs_data>-cost1.
        gt_list-cost2b =  <lfs_data>-cost2.
        gt_list-cost3b =  <lfs_data>-cost3.
        gt_list-cost4b =  <lfs_data>-cost4.
  ***********add by xx-yangyu begin 27.03.2021 11:15:53 ****************
        gt_list-cost5b =  <lfs_data>-cost5.
        gt_list-cost6b =  <lfs_data>-cost6.
        gt_list-cost7b =  <lfs_data>-cost7.
        gt_list-cost8b =  <lfs_data>-cost8.
  ***********add end  27.03.2021 11:15:53*******************************
        APPEND gt_list.
        CLEAR  gt_list.
      ENDIF.
    ENDLOOP.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form frm_adjust_data
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_adjust_data .
  *  DATA: lt_data TYPE TABLE OF zsy_d_figl017,
  *        ls_data TYPE zsy_d_figl017.
  *  DATA: lv_gjahr1 TYPE gjahr, "上年同期年
  *        lv_monat1 TYPE monat, "上年同期月
  *        lv_gjahr2 TYPE gjahr, "上月期末年
  *        lv_monat2 TYPE monat, "上月期末月
  *        lv_gjahr3 TYPE gjahr, "年初年
  *        lv_monat3 TYPE monat. "年初月
  *  DATA: lv_itemnoa    TYPE ergsl,
  *        lv_itemnob    TYPE ergsl,
  *        lv_itemnum    TYPE numc3, "序号，用于比较
  *        lv_ergsl_left TYPE numc3,
  *        lv_tabix      TYPE sy-tabix.
  ** 用于汇总项统计
  *  DATA: lv_next TYPE ergsl.
  *  DATA: lv_hslvt1a TYPE hslvt,
  *        lv_hslvt2a TYPE hslvt,
  *        lv_hslvt3a TYPE hslvt,
  *        lv_hslvt4a TYPE hslvt,
  *        lv_hslvt1b TYPE hslvt,
  *        lv_hslvt2b TYPE hslvt,
  *        lv_hslvt3b TYPE hslvt,
  *        lv_hslvt4b TYPE hslvt.
  *
  *  CLEAR lt_data.
  *  SELECT *
  *  INTO TABLE lt_data
  *  FROM zsy_d_figl017
  *  WHERE bukrs IN s_bukrs
  *  AND prctr IN s_prctr[]
  *  AND ( ( gjahr EQ p_gjahr AND monat LE p_monat )
  *  OR gjahr LT p_gjahr )
  *  AND zbs EQ 'X'.
  *
  *  IF lt_data IS NOT INITIAL.
  *    "上年同期
  *    lv_gjahr1 = p_gjahr - 1.
  *    lv_monat1 = p_monat.
  *
  *    "上月期末数
  *    IF p_monat EQ '01'.
  *      lv_gjahr2 = p_gjahr - 1.
  *      lv_monat2 = '16'.
  *    ELSE.
  *      lv_gjahr2 = p_gjahr.
  *      lv_monat2 = p_monat - 1.
  *    ENDIF.
  *
  *    "年初数
  *    lv_gjahr3 = p_gjahr - 1.
  *    lv_monat3 = '16'.
  *
  *    CLEAR lv_ergsl_left.
  *    lv_ergsl_left = gc_ergsl_left.
  *    LOOP AT gt_list.
  *      CLEAR lv_tabix.
  *      lv_tabix = sy-tabix.
  *      CLEAR: lv_itemnoa,lv_itemnob.
  *      lv_itemnoa = gt_list-zzzxca.
  *      lv_itemnob = gt_list-zzzxcb.
  *      SHIFT lv_itemnoa LEFT DELETING LEADING '0'.
  *      SHIFT lv_itemnob LEFT DELETING LEADING '0'.
  *
  *      "合计项统计
  *      CLEAR: lv_hslvt1a,lv_hslvt2a,lv_hslvt3a,lv_hslvt4a,
  *      lv_hslvt1b,lv_hslvt2b,lv_hslvt3b,lv_hslvt4b.
  *      "上年同期
  *      LOOP AT lt_data INTO ls_data WHERE gjahr EQ lv_gjahr1 AND monat EQ lv_monat1
  *      AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *      AND zqcqm = ''.
  *        CLEAR: lv_itemnum.
  *        lv_itemnum = ls_data-zitemno.
  *        IF lv_itemnum LE lv_ergsl_left.
  *          gt_list-cost1a = gt_list-cost1a + ls_data-hslvt.
  *          lv_hslvt1a = lv_hslvt1a + ls_data-hslvt.
  *        ELSE.
  *          gt_list-cost1b = gt_list-cost1b + ls_data-hslvt * ( - 1 ).
  *          lv_hslvt1b = lv_hslvt1b + ls_data-hslvt * ( - 1 ).
  *        ENDIF.
  *      ENDLOOP.
  *
  *      "上月期末数
  *      IF lv_monat2 EQ '16'.
  *        LOOP AT lt_data INTO ls_data WHERE gjahr EQ lv_gjahr2 AND ( monat BETWEEN '12' AND '16' )
  *        AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *        AND zqcqm = ''.
  *          CLEAR: lv_itemnum.
  *          lv_itemnum = ls_data-zitemno.
  *          IF lv_itemnum LE lv_ergsl_left.
  *            gt_list-cost2a = gt_list-cost2a + ls_data-hslvt.
  *            lv_hslvt2a = lv_hslvt2a + ls_data-hslvt.
  *          ELSE.
  *            gt_list-cost2b = gt_list-cost2b + ls_data-hslvt * ( - 1 ).
  *            lv_hslvt2b = lv_hslvt2b + ls_data-hslvt * ( - 1 ).
  *          ENDIF.
  *        ENDLOOP.
  *      ELSE.
  *        LOOP AT lt_data INTO ls_data WHERE gjahr EQ lv_gjahr2 AND monat EQ lv_monat2
  *        AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *        AND zqcqm = ''.
  *          CLEAR: lv_itemnum.
  *          lv_itemnum = ls_data-zitemno.
  *          IF lv_itemnum LE lv_ergsl_left.
  *            gt_list-cost2a = gt_list-cost2a + ls_data-hslvt.
  *            lv_hslvt2a = lv_hslvt2a + ls_data-hslvt.
  *          ELSE.
  *            gt_list-cost2b = gt_list-cost2b + ls_data-hslvt * ( - 1 ).
  *            lv_hslvt2b = lv_hslvt2b + ls_data-hslvt * ( - 1 ).
  *          ENDIF.
  *        ENDLOOP.
  *      ENDIF.
  *
  *      "年初数
  *      lv_monat3 = '16'.
  *      DO.
  *        CLEAR ls_data.
  *        LOOP AT lt_data INTO ls_data WHERE gjahr EQ lv_gjahr3 AND monat EQ lv_monat3
  *        AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *        AND zqcqm = ''.
  *          CLEAR: lv_itemnum.
  *          lv_itemnum = ls_data-zitemno.
  *          IF lv_itemnum LE lv_ergsl_left.
  **            gt_list-cost3a = gt_list-cost3a + ls_data-hslvt.
  *            IF p_rb_03 EQ ''.
  *              gt_list-cost3a = gt_list-cost3a + ls_data-hslvt.
  *            ENDIF.
  *            lv_hslvt3a = lv_hslvt3a + ls_data-hslvt.
  *            gt_list-cost5a = lv_hslvt3a.
  *          ELSE.
  **            gt_list-cost3b = gt_list-cost3b + ls_data-hslvt * ( - 1 ).
  *            IF p_rb_03 EQ ''.
  *              gt_list-cost3b = gt_list-cost3b + ls_data-hslvt * ( - 1 ).
  *            ENDIF.
  *            lv_hslvt3b = lv_hslvt3b + ls_data-hslvt * ( - 1 ).
  *            gt_list-cost5b = lv_hslvt3b.
  *          ENDIF.
  *        ENDLOOP.
  *        IF ls_data-hslvt NE 0 OR lv_monat3 LE '12'.
  *          EXIT.
  *        ENDIF.
  *        lv_monat3 = lv_monat3 - 1.
  *      ENDDO.
  *      CLEAR ls_data.
  *      LOOP AT lt_data INTO ls_data WHERE gjahr EQ p_gjahr AND monat LE p_monat
  *      AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *      AND zqcqm = 'X'.
  *        CLEAR: lv_itemnum.
  *        lv_itemnum = ls_data-zitemno.
  *        IF lv_itemnum LE lv_ergsl_left.
  *          IF p_rb_03 EQ ''.
  *            gt_list-cost3a = gt_list-cost3a + ls_data-hslvt.
  *          ENDIF.
  *          lv_hslvt3a = lv_hslvt3a + ls_data-hslvt.
  *          gt_list-cost5a = lv_hslvt3a.
  *        ELSE.
  *          IF p_rb_03 EQ ''.
  *            gt_list-cost3b = gt_list-cost3b + ls_data-hslvt * ( - 1 ).
  *          ENDIF.
  *          lv_hslvt3b = lv_hslvt3b + ls_data-hslvt * ( - 1 ).
  *          gt_list-cost5b = lv_hslvt3b.
  *        ENDIF.
  *      ENDLOOP.
  *
  *      "期末数
  *      LOOP AT lt_data INTO ls_data WHERE gjahr EQ p_gjahr AND monat EQ p_monat
  *      AND ( zitemno EQ lv_itemnoa OR zitemno EQ lv_itemnob )
  *      AND zqcqm = ''.
  *        CLEAR: lv_itemnum.
  *        lv_itemnum = ls_data-zitemno.
  *        IF lv_itemnum LE lv_ergsl_left.
  **          gt_list-cost4a = gt_list-cost4a + ls_data-hslvt.
  *          IF p_rb_03 EQ ''.
  *            gt_list-cost4a = gt_list-cost4a + ls_data-hslvt.
  *          ENDIF.
  *          lv_hslvt4a = lv_hslvt4a + ls_data-hslvt.
  *          gt_list-cost6a = lv_hslvt4a.
  *        ELSE.
  **          gt_list-cost4b = gt_list-cost4b + ls_data-hslvt * ( - 1 ).
  *          IF p_rb_03 EQ ''.
  *            gt_list-cost4b = gt_list-cost4b + ls_data-hslvt * ( - 1 ).
  *          ENDIF.
  *          lv_hslvt4b = lv_hslvt4b + ls_data-hslvt * ( - 1 ).
  *          gt_list-cost6b = lv_hslvt4b.
  *        ENDIF.
  *      ENDLOOP.
  *      "从利润表中获取的调整的部分
  *      IF gt_list-zzzxcb EQ '0000000068'.
  *        gt_list-cost5b = gt_list-cost5b - gv_p68_adj01.
  *        gt_list-cost6b = gt_list-cost6b - gv_p68_adj02.
  *        lv_hslvt3b = lv_hslvt3b - gv_p68_adj01.
  *        lv_hslvt4b = lv_hslvt4b - gv_p68_adj02.
  *      ENDIF.
  *      MODIFY gt_list INDEX lv_tabix.
  *
  **--------------------------------------------------------------------*
  **合计项统计
  *      CLEAR: lv_itemnoa,lv_itemnob.
  *      lv_itemnoa = gt_list-zzzxca.
  *      lv_itemnob = gt_list-zzzxcb.
  *
  *      IF lv_hslvt1a IS NOT INITIAL OR lv_hslvt2a IS NOT INITIAL
  *      OR lv_hslvt3a IS NOT INITIAL OR lv_hslvt4a IS NOT INITIAL.
  *        CLEAR lv_next.
  *        DO.
  *          IF lv_next IS NOT INITIAL.
  *            lv_itemnoa = lv_next.
  *          ENDIF.
  *          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  *            EXPORTING
  *              input  = lv_itemnoa
  *            IMPORTING
  *              output = lv_itemnoa.
  **          IF lv_itemnoa EQ '0000000001' OR lv_itemnoa EQ '0000000015'
  **            OR lv_itemnoa EQ '0000000016' OR lv_itemnoa EQ '0000000035'.
  **            lv_next = '0000000037'.
  **          ELSEIF lv_itemnoa GE '0000000002' AND lv_itemnoa LE '0000000014'.
  **            lv_next = '0000000015'.
  **          ELSEIF lv_itemnoa GE '0000000017' AND lv_itemnoa LE '0000000036'.
  **            lv_next = '0000000035'.
  **          ELSEIF lv_itemnoa EQ '0000000037'.
  **            EXIT.
  **          ENDIF.
  *
  *          "模板调整
  *          IF lv_itemnoa EQ '0000000001' OR lv_itemnoa EQ '0000000015'
  *          OR lv_itemnoa EQ '0000000016' OR lv_itemnoa EQ '0000000035'.
  *            lv_next = '0000000036'.
  *          ELSEIF lv_itemnoa GE '0000000002' AND lv_itemnoa LE '0000000014'.
  *            lv_next = '0000000015'.
  *          ELSEIF lv_itemnoa GE '0000000017' AND lv_itemnoa LE '0000000034'.
  *            lv_next = '0000000035'.
  *          ELSEIF lv_itemnoa EQ '0000000036'.
  *            EXIT.
  *          ENDIF.
  *          READ TABLE gt_list WITH KEY zzzxca = lv_next.
  *          IF sy-subrc EQ 0.
  *            CLEAR lv_tabix.
  *            lv_tabix = sy-tabix.
  *            gt_list-cost1a = gt_list-cost1a + lv_hslvt1a.
  *            gt_list-cost2a = gt_list-cost2a + lv_hslvt2a.
  *            IF p_rb_03 EQ ''.
  *              gt_list-cost3a = gt_list-cost3a + lv_hslvt3a.
  *              gt_list-cost4a = gt_list-cost4a + lv_hslvt4a.
  *            ELSE.
  *              gt_list-cost5a = gt_list-cost5a + lv_hslvt3a.
  *              gt_list-cost6a = gt_list-cost6a + lv_hslvt4a.
  *            ENDIF.
  *            MODIFY gt_list INDEX lv_tabix.
  *          ENDIF.
  *        ENDDO.
  *      ENDIF.
  *
  *      IF lv_hslvt1b IS NOT INITIAL OR lv_hslvt2b IS NOT INITIAL
  *      OR lv_hslvt3b IS NOT INITIAL OR lv_hslvt4b IS NOT INITIAL.
  *        CLEAR lv_next.
  *        DO.
  *          IF lv_next IS NOT INITIAL.
  *            lv_itemnob = lv_next.
  *          ENDIF.
  *          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  *            EXPORTING
  *              input  = lv_itemnob
  *            IMPORTING
  *              output = lv_itemnob.
  **          IF lv_itemnob EQ '0000000063' OR lv_itemnob EQ '0000000064'
  **            OR lv_itemnob EQ '0000000071'.
  **            lv_next = '0000000074'.
  **          ELSEIF lv_itemnob EQ '0000000038' OR lv_itemnob EQ '0000000053'
  **            OR lv_itemnob EQ '0000000054' OR lv_itemnob EQ '0000000062'.
  **            lv_next = '0000000063'.
  **          ELSEIF lv_itemnob GE '0000000039' AND lv_itemnob LE '0000000052'.
  **            lv_next = '0000000053'.
  **          ELSEIF lv_itemnob GE '0000000055' AND lv_itemnob LE '0000000061'.
  **            lv_next = '0000000062'.
  **          ELSEIF lv_itemnob GE '0000000065' AND lv_itemnob LE '0000000070'.
  **            lv_next = '0000000071'.
  **          ELSEIF lv_itemnob GE '0000000072' AND lv_itemnob LE '0000000073'.
  **            lv_next = '0000000071'.
  **          ELSEIF lv_itemnob EQ '0000000074'.
  **            EXIT.
  **          ENDIF.
  *
  *          "模板调整
  *          IF lv_itemnob EQ '0000000062' OR lv_itemnob EQ '0000000063'
  *          OR lv_itemnob EQ '0000000069'.
  *            lv_next = '0000000072'.
  *          ELSEIF lv_itemnob EQ '0000000037' OR lv_itemnob EQ '0000000052'
  *            OR lv_itemnob EQ '0000000053' OR lv_itemnob EQ '0000000061'.
  *            lv_next = '0000000062'.
  *          ELSEIF lv_itemnob GE '0000000038' AND lv_itemnob LE '0000000051'.
  *            lv_next = '0000000052'.
  *          ELSEIF lv_itemnob GE '0000000054' AND lv_itemnob LE '0000000060'.
  *            lv_next = '0000000061'.
  *          ELSEIF lv_itemnob GE '0000000064' AND lv_itemnob LE '0000000068'.
  *            lv_next = '0000000069'.
  *          ELSEIF lv_itemnob GE '0000000070' AND lv_itemnob LE '0000000071'.
  *            lv_next = '0000000069'.
  *          ELSEIF lv_itemnob EQ '0000000072'.
  *            EXIT.
  *          ENDIF.
  *
  *          READ TABLE gt_list WITH KEY zzzxcb = lv_next.
  *          IF sy-subrc EQ 0.
  *            CLEAR lv_tabix.
  *            lv_tabix = sy-tabix.
  *            gt_list-cost1b = gt_list-cost1b + lv_hslvt1b.
  *            gt_list-cost2b = gt_list-cost2b + lv_hslvt2b.
  *            IF p_rb_03 EQ ''.
  *              gt_list-cost3b = gt_list-cost3b + lv_hslvt3b.
  *              gt_list-cost4b = gt_list-cost4b + lv_hslvt4b.
  *            ELSE.
  *              gt_list-cost5b = gt_list-cost5b + lv_hslvt3b.
  *              gt_list-cost6b = gt_list-cost6b + lv_hslvt4b.
  *            ENDIF.
  *            MODIFY gt_list INDEX lv_tabix.
  *          ENDIF.
  *        ENDDO.
  *      ENDIF.
  *      CLEAR gt_list.
  *    ENDLOOP.
  *  ENDIF.
  *  LOOP AT gt_list.
  *    CLEAR lv_tabix.
  *    lv_tabix = sy-tabix.
  *    gt_list-cost7a = gt_list-cost3a + gt_list-cost5a.
  *    gt_list-cost8a = gt_list-cost4a + gt_list-cost6a.
  *    gt_list-cost7b = gt_list-cost3b + gt_list-cost5b.
  *    gt_list-cost8b = gt_list-cost4b + gt_list-cost6b.
  *    MODIFY gt_list INDEX lv_tabix.
  *  ENDLOOP.

  *  DATA: lv_hslvt5b TYPE hslvt,
  *        lv_hslvt6b TYPE hslvt,
  *        lv_hslvt7b TYPE hslvt,
  *        lv_hslvt8b TYPE hslvt.
  *  "特殊项处理： 其中:归属于母公司的权益    70 = 69 - 71
  *  CLEAR: lv_hslvt1b,lv_hslvt2b,lv_hslvt3b,lv_hslvt4b.
  *  LOOP AT gt_list WHERE zzzxcb EQ '0000000069' OR zzzxcb EQ '0000000071'.
  *    CASE gt_list-zzzxcb.
  *      WHEN '0000000069'.
  *        lv_hslvt1b = lv_hslvt1b + gt_list-cost1b.
  *        lv_hslvt2b = lv_hslvt2b + gt_list-cost2b.
  *        lv_hslvt3b = lv_hslvt3b + gt_list-cost3b.
  *        lv_hslvt4b = lv_hslvt4b + gt_list-cost4b.
  *        lv_hslvt5b = lv_hslvt5b + gt_list-cost5b.
  *        lv_hslvt6b = lv_hslvt6b + gt_list-cost6b.
  *        lv_hslvt7b = lv_hslvt7b + gt_list-cost7b.
  *        lv_hslvt8b = lv_hslvt8b + gt_list-cost8b.
  *      WHEN '0000000071'.
  *        lv_hslvt1b = lv_hslvt1b - gt_list-cost1b.
  *        lv_hslvt2b = lv_hslvt2b - gt_list-cost2b.
  *        lv_hslvt3b = lv_hslvt3b - gt_list-cost3b.
  *        lv_hslvt4b = lv_hslvt4b - gt_list-cost4b.
  *        lv_hslvt5b = lv_hslvt5b - gt_list-cost5b.
  *        lv_hslvt6b = lv_hslvt6b - gt_list-cost6b.
  *        lv_hslvt7b = lv_hslvt7b - gt_list-cost7b.
  *        lv_hslvt8b = lv_hslvt8b - gt_list-cost8b.
  *      WHEN OTHERS.
  *    ENDCASE.
  *  ENDLOOP.
  *
  *  READ TABLE gt_list WITH KEY zzzxcb = '0000000070'.
  *  IF sy-subrc EQ 0.
  *    CLEAR lv_tabix.
  *    lv_tabix = sy-tabix.
  *    gt_list-cost1b = lv_hslvt1b.
  *    gt_list-cost2b = lv_hslvt2b.
  *    gt_list-cost3b = lv_hslvt3b.
  *    gt_list-cost4b = lv_hslvt4b.
  *    gt_list-cost5b = lv_hslvt5b.
  *    gt_list-cost6b = lv_hslvt6b.
  *    gt_list-cost7b = lv_hslvt7b.
  *    gt_list-cost8b = lv_hslvt8b.
  *    MODIFY gt_list INDEX lv_tabix.
  *  ENDIF.
  ***********add end  29.01.2021 15:37:55*******************************
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_GET_TEXT
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *&      --> GT_DATA_STUFE
  *&      <-- GT_DATA_TXT45
  *&---------------------------------------------------------------------*
  FORM frm_get_text  USING p_stufe TYPE rf011p-stufe  p_top TYPE rf011p-ergsl CHANGING p_txt45 TYPE rf011q-txt45.
    DATA:lv_stufe TYPE i,
         lv_text  TYPE rf011q-txt45.
  
    IF p_txt45 = '空行'.
      p_txt45 = ''.
      EXIT.
    ENDIF.
  
    lv_stufe = p_stufe.
    lv_stufe = lv_stufe - 1.
    CLEAR:lv_text.
  
    DO lv_stufe TIMES.
      lv_text = gc_blank && lv_text.
    ENDDO.
  
    p_txt45 = lv_text &&  p_txt45.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_ADD_I011Z
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *&      --> P_
  *&      --> P_
  *&      --> P_
  *&---------------------------------------------------------------------*
  FORM frm_add_i011z  USING  p_ergso TYPE rf011z-ergso
        p_vonkt TYPE rf011z-vonkt
        p_bilkt TYPE rf011z-bilkt.
    gt_i011z-ergso = p_ergso.
    gt_i011z-vonkt = p_vonkt.
    gt_i011z-bilkt = p_bilkt.
    APPEND gt_i011z.
    CLEAR  gt_i011z.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *& Form FRM_DISPLAY_DATA
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *& -->  p1        text
  *& <--  p2        text
  *&---------------------------------------------------------------------*
  FORM frm_display_data.
    CLEAR:gs_fieldcat,gs_fieldcat[].
  
    PERFORM frm_field   USING   'TXT45A'     '资产'                ''   'L'.
    PERFORM frm_field   USING   'ZZZXCA'     '行次'                'X'  'C'.
  *  IF p_rb_02 = 'X'.
  *    PERFORM frm_field   USING   'COST1A'     '上年同期数'          'X'  'R'.
  *    PERFORM frm_field   USING   'COST2A'     '上月期末数'          'X'  'R'.
  *  ENDIF.
  **  PERFORM frm_field   USING   'COST3A'     '年初数'              'X'  'R'.
  **  PERFORM frm_field   USING   'COST4A'     '期末数'              'X'  'R'.
  *  IF p_rb_03 EQ ''.
    PERFORM frm_field   USING   'COST3A'     '年初数'              'X'  'R'.
    PERFORM frm_field   USING   'COST4A'     '期末数'              'X'  'R'.
  *  ELSE.
  *    PERFORM frm_field   USING   'COST3A'     '账面年初数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST4A'     '账面期末数'              'X'  'R'.
  *  ENDIF.
  *  IF p_rb_03 EQ 'X'.
  *    PERFORM frm_field   USING   'COST5A'     '调整年初数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST6A'     '调整期末数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST7A'     '调整后年初数'            'X'  'R'.
  *    PERFORM frm_field   USING   'COST8A'     '调整后期末数'            'X'  'R'.
  *  ENDIF.
    PERFORM frm_field   USING   'TXT45B'     '负债及所有者权益'    ''   'L'.
    PERFORM frm_field   USING   'ZZZXCB'     '行次'                'X'  'C'.
  *  IF p_rb_02 = 'X'.
  *    PERFORM frm_field   USING   'COST1B'     '上年同期数'          'X'  'R'.
  *    PERFORM frm_field   USING   'COST2B'     '上月期末数'          'X'  'R'.
  *  ENDIF.
  **  PERFORM frm_field   USING   'COST3B'     '年初数'              'X'  'R'.
  **  PERFORM frm_field   USING   'COST4B'     '期末数'              'X'  'R'.
  *
  *  IF p_rb_03 EQ ''.
    PERFORM frm_field   USING   'COST3B'     '年初数'              'X'  'R'.
    PERFORM frm_field   USING   'COST4B'     '期末数'              'X'  'R'.
  *  ELSE.
  *    PERFORM frm_field   USING   'COST3B'     '账面年初数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST4B'     '账面期末数'              'X'  'R'.
  *  ENDIF.
  *
  *  IF p_rb_03 EQ 'X'.
  *    PERFORM frm_field   USING   'COST5B'     '调整年初数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST6B'     '调整期末数'              'X'  'R'.
  *    PERFORM frm_field   USING   'COST7B'     '调整后年初数'            'X'  'R'.
  *    PERFORM frm_field   USING   'COST8B'     '调整后期末数'            'X'  'R'.
  *  ENDIF.
    PERFORM frm_layout  TABLES gt_list USING 'PF_STATUS' 'USER_COMMAND'.
  ENDFORM.
  *&---------------------------------------------------------------------*
  *&      Form  FRM_FIELD
  *&---------------------------------------------------------------------*
  *       text
  *----------------------------------------------------------------------*
  *----------------------------------------------------------------------*
  FORM frm_field  USING p_fieldname p_coltext p_no_zero p_just.
    DATA:as_fieldcat   TYPE lvc_s_fcat.
  
    as_fieldcat-fieldname   = p_fieldname.
    as_fieldcat-coltext     = p_coltext.
    as_fieldcat-no_zero     = p_no_zero.
    as_fieldcat-just        = p_just.
  
    APPEND as_fieldcat TO gs_fieldcat.
    CLEAR as_fieldcat.
  ENDFORM.                    " FRM_FIELD
  *&---------------------------------------------------------------------*
  *&      Form  FRM_LAYOUT
  *&---------------------------------------------------------------------*
  *       text
  *----------------------------------------------------------------------*
  *----------------------------------------------------------------------*
  FORM frm_layout TABLES p_data USING p_status p_command.
    gs_repid              = sy-repid.
    gs_layout-zebra       = 'X'.
    gs_layout-cwidth_opt  = 'X'.
  
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        i_callback_program          = gs_repid
        i_save                      = 'A'
        it_fieldcat_lvc             = gs_fieldcat[]
        it_sort_lvc                 = gs_sortinfo[]
        is_layout_lvc               = gs_layout
        i_callback_pf_status_set    = p_status
        i_callback_html_top_of_page = 'FRM_TOP_OF_PAGE'
        i_html_height_top           = 15     "HTML框的高度
      TABLES
        t_outtab                    = p_data
      EXCEPTIONS
        program_error               = 1
        OTHERS                      = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDFORM.                    "frm_layout
  *&---------------------------------------------------------------------*
  *&      FORM  PF_STATUS
  *&---------------------------------------------------------------------*
  *       TEXT
  *----------------------------------------------------------------------*
  *      -->RT_EXTAB   TEXT
  *----------------------------------------------------------------------*
  
  FORM pf_status USING rt_extab TYPE slis_t_extab.
    DATA:lt_cmd   TYPE STANDARD TABLE OF sy-ucomm.
  
  *  IF p_rb_02 = 'X'.
  *    APPEND 'CMD_PRINT' TO lt_cmd.
  *  ENDIF.
  *  SET PF-STATUS 'MYBUTTON' EXCLUDING lt_cmd.
  ENDFORM.                    "PF_STATUS
  *&---------------------------------------------------------------------*
  *&      FORM  TOP_OF_PAGE
  *&---------------------------------------------------------------------*
  *       TEXT
  *----------------------------------------------------------------------*
  FORM frm_top_of_page USING document TYPE REF TO cl_dd_document.
    DATA:lv_str1 TYPE string,
         lv_str2 TYPE string,
         lv_str3 TYPE string.
    DATA:lv_idx0 TYPE i,
         lv_idx1 TYPE i,
         lv_idx2 TYPE i,
         lv_idx3 TYPE i.
  
    CASE 'X'.
      WHEN p_rb_01.
        lv_idx0 = '60'.
        lv_idx1 = '0'.
        lv_idx2 = '20'.
        lv_idx3 = '40'.
      WHEN p_rb_02.
        lv_idx0 = '110'.
        lv_idx1 = '0'.
        lv_idx2 = '70'.
        lv_idx3 = '80'.
    ENDCASE.
  
    PERFORM frm_create_page USING document lv_idx0  '资产负债表' ''.
    CALL METHOD document->new_line.
    CALL METHOD document->new_line.
  
    lv_str1 = '单位：' && gv_butxt.
    PERFORM frm_create_page USING document lv_idx1   lv_str1  ''.
  
    lv_str2 = '日期：' && gv_zdate+0(4) && '-' && gv_zdate+4(2) && '-' && gv_zdate+6(2).
    PERFORM frm_create_page USING document lv_idx2   lv_str2  ''.
  
    lv_str3 = '单位：' && gv_danwei.
    PERFORM frm_create_page USING document lv_idx3   lv_str3  ''.
  ENDFORM.                    "TOP_OF_PAGE
  
  *&---------------------------------------------------------------------*
  *&      FORM  FRM_CREATE_PAGE
  *&---------------------------------------------------------------------*
  *       TEXT
  *----------------------------------------------------------------------*
  *      -->P_100    TEXT
  *      -->P_TEXT  TEXT
  *      -->P_1062   TEXT
  *----------------------------------------------------------------------*
  FORM frm_create_page  USING   document TYPE REF TO cl_dd_document p_width p_text p_style.
    DATA: s_text TYPE sdydo_text_element.
  
    s_text = p_text.
    CALL METHOD document->add_gap
      EXPORTING
        width = p_width.
    CALL METHOD document->add_text
      EXPORTING
        text      = s_text
        sap_style = p_style.
  ENDFORM.                    " FRM_CREATE_PAGE
  *&---------------------------------------------------------------------*
  *&      Form  FRM_ALPHA_INPUT
  *&---------------------------------------------------------------------*
  *       text
  *----------------------------------------------------------------------*
  *      -->P_P_ALPHA  text
  *      <--P_P_ALPHA  text
  *----------------------------------------------------------------------*
  FORM frm_alpha_input CHANGING p_str.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = p_str
      IMPORTING
        output = p_str.
  ENDFORM.                    " FRM_ALPHA_INPUT
  *&---------------------------------------------------------------------*
  *& Form FRM_LAST_DAY_OF_MONTHS
  *&---------------------------------------------------------------------*
  *& text
  *&---------------------------------------------------------------------*
  *&      --> GV_DATE2
  *&      <-- GV_DATE3
  *&---------------------------------------------------------------------*
  FORM frm_last_day_of_months  USING    p_date_in TYPE sy-datum CHANGING p_date_out TYPE sy-datum.
    CALL FUNCTION 'LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in            = p_date_in
      IMPORTING
        last_day_of_month = p_date_out
      EXCEPTIONS
        day_in_no_date    = 1
        OTHERS            = 2.
    IF sy-subrc <> 0.
    ENDIF.
  ENDFORM.